package com.example.controller;

import com.example.common.result.PageResult;
import com.example.common.result.Result;
import com.example.entity.dto.IHeadDTO;
import com.example.entity.dto.IHeadPageDTO;
import com.example.entity.dto.Pojo;
import com.example.service.IHeadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/ihead")
@Api(tags = "检验结果相关接口")
public class IHeadController {

    @Resource
    private IHeadService iHeadService;

    @ApiOperation("新增检验")
    @PostMapping("/add")
    public Result add(@RequestBody IHeadDTO iHeadDTO){
        System.out.println(iHeadDTO.toString());
        iHeadService.add(iHeadDTO);
        return Result.success("成功");
    }

    @ApiOperation("查看检验详情")
    @GetMapping ("/all")
    public Result<IHeadDTO> getAll(Long uid){
        IHeadDTO iHeadDTO = iHeadService.getAll(uid);
        return Result.ok(iHeadDTO);
    }

    @ApiOperation("查看检验详情(UDF05为Y) 通过单号")
    @GetMapping ("/allId")
    public Result<IHeadDTO> allId(Long uid){
        IHeadDTO iHeadDTO = iHeadService.allId(uid);
        return Result.ok(iHeadDTO);
    }

    @ApiOperation("查看检验详情(UDF05为Y) 通过品号")
    @PostMapping ("/allIds")
    public Result<List<IHeadDTO>> allIds(@RequestBody Pojo pojo){
        List<IHeadDTO> list = iHeadService.allIds(pojo);
        return Result.ok(list);
    }

    @ApiOperation("查看详情列表")
    @GetMapping("/alllist")
    public Result<List<IHeadDTO>> getAlllist(@RequestParam("ids") List<Long> ids){
        List<IHeadDTO> list = iHeadService.getAlllList(ids);
        return Result.ok(list);
    }

    @ApiOperation("分页获取单头详细信息")
    @GetMapping("/page")
    public Result<PageResult> page(IHeadPageDTO iHeadPageDTO){
        PageResult pageResult  = iHeadService.page(iHeadPageDTO);
        return Result.ok(pageResult);
    }

}
